#define _CRT_SECURE_NO_WARNINGS  1
#include<stdio.h>
#include<stdlib.h>
typedef struct Lnode
{
	int data;
	struct Lnode* next;
}Lnode;


void creatlist(Lnode** phead, int* arr, int n)
{
	int i = 0;
	for (i = 0; i < n; i++)
	{
		Lnode* node = (Lnode*)malloc(sizeof(Lnode));
		node->data = arr[i];
		node->next = NULL;

		if (*phead == NULL)
		{
			*phead = node;
		}

		else
		{
			Lnode* tail = *phead;
			while (tail->next)
			{
				tail = tail->next;
			}
			tail->next = node;
		}
		
	}
}

void swap(Lnode** phead)
{
	Lnode* p = *phead;
	Lnode* s = p->next;	
	int k = s->data;
	s->data = p->data;
	p->data = k;


	Lnode* m = *phead;
	while (m->next->next)
	{
		m = m->next;
	}
	Lnode* n = m->next;
    k = m->data;
	m->data = n->data;
	n->data = k;
}
int main()
{
	int n = 0;
	int i = 0;
	scanf("%d", &n);
	int arr[101] = { 0 };
	for (i = 0; i < n; i++)
	{
		scanf("%d", &arr[i]);
	}
	Lnode* phead = NULL;
	creatlist(&phead,arr,n);


	Lnode* cur = phead;
	while (cur)
	{
		printf("%d->", cur->data);
		cur = cur->next;
	}
	printf("NULL\n");


	swap(&phead);
	cur = phead;
	while (cur)
	{
		printf("%d->", cur->data);
		cur = cur->next;
	}
	printf("NULL\n");

}